let fs = require("fs");
let archiver = require("archiver");
const path = require("path");
const fse = require("fs-extra");
const compress = () => {
	return new Promise((resolve, reject) => {
		let outPutPath = path.resolve(__dirname, "../public");
		fse.ensureDirSync(outPutPath);
		let output = fs.createWriteStream(
			path.resolve(__dirname, "../public/xinxin.zip")
		);
		let archive = archiver("zip", {
			zlib: { level: 9 }
		});

		output.on("close", function() {
	
			resolve();
		});

		output.on("end", function() {
	
		});

		archive.on("warning", function(err) {
			if (err.code === "ENOENT") {
				// log warning
			} else {
				reject(err);
			}
		});

		archive.on("error", function(err) {
			reject(err);
		});

		archive.pipe(output);
		archive.directory(path.resolve(__dirname, "../tmp/"), false);
		archive.finalize();
	});
};
//compress
module.exports = { compress };
